﻿using Domain.Entity.Config;
using Domain.Repository.IConfig;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EFCore.Repository.Config
{
    public class EMRRepository : IEngage_major_releaseRepository
    {
        private readonly MyDbContext emrRepository;

        public EMRRepository(MyDbContext emrRepository)
        {
            this.emrRepository = emrRepository;
        }

        public async Task<int> AddEMRAsync(Engage_major_release emr)
        {
            emrRepository.engage_Major_Releases.Add(emr);
            int ok=await emrRepository.SaveChangesAsync();
            return ok;
        }

        public async Task<int> DeleteEMRAsync(int id)
        {
            Engage_major_release sc = new Engage_major_release()
            {
                Mre_id=id
            };
            emrRepository.engage_Major_Releases.Remove(sc);
            int ok = await emrRepository.SaveChangesAsync();
            return ok;
        }

        public async Task<int> GetCount()
        {
            var tooc=emrRepository.engage_Major_Releases.Count();
            return tooc;
        }

        public async Task<List<Engage_major_release>> GetEMR()
        {
            return  emrRepository.engage_Major_Releases.ToList();
        }

        public async Task<List<Engage_major_release>> GetList(int page, int pageSize)
        {
           var chances=emrRepository.engage_Major_Releases.Skip((page-1)*pageSize).Take(pageSize).ToList();
            return chances;
        }

        public async Task<int> UpdateEMRAsync(Engage_major_release emr)
        {
            Engage_major_release ok1 = emrRepository.engage_Major_Releases.Where(e => e.Mre_id == emr.Mre_id).FirstOrDefault();
            ok1.Human_amount = emr.Human_amount;
            ok1.deadline = emr.deadline;
            ok1.Changer = emr.Changer;
            ok1.ChangeTime= emr.ChangeTime;
            ok1.Major_describe= emr.Major_describe;
            ok1.Engage_required = emr.Engage_required;
            emrRepository.engage_Major_Releases.Update(ok1);
            int cct = await emrRepository.SaveChangesAsync();
            return cct;
        }
    }
}
